import { createI18n } from 'vue-i18n' // import from runtime only

// import { getLanguage } from '@/utils/cookies'

import elementEnLocale from 'element-plus/es/locale/lang/en'
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn'

// User defined lang
import enLocale from './en'
import zhLocale from './zh-cn'

const messages = {
  en: {
    ...enLocale,
    ...elementEnLocale
  },
  'zh-cn': {
    ...zhLocale,
    ...elementZhLocale
  }
}

export const getLocale = () => {
  // const cookieLanguage = getLanguage()
  // const cookieLanguage = null
  // if (cookieLanguage) {
  //   return cookieLanguage
  // }
  // const language = navigator.language.toLowerCase()
  // const locales = Object.keys(messages)
  // for (const locale of locales) {
  //   if (language.indexOf(locale) > -1) {
  //     return locale
  //   }
  // }

  // Default language is english
  return 'zh'
}

const i18n = createI18n({
  legacy: false,
  locale: getLocale(),
  messages
})

export default i18n
